package Controller;
import Service.VirtualProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/product")
public class VirtualProductController {
    @Autowired
    private VirtualProductService productService;

    @GetMapping("/list")
    public String list(Model model) {
        model.addAttribute("products", productService.findAll());
        return "product_list";
    }

    @GetMapping("/byCategory")
    public String listByCategory(@RequestParam Long cid, Model model) {
        model.addAttribute("products", productService.findByCategory(cid));
        return "product_list";
    }

    @GetMapping("/detail")
    public String detail(@RequestParam Long id, Model model) {
        model.addAttribute("product", productService.findById(id));
        return "product_detail";
    }
}